<script setup>
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import NewShopAuthService from '../services/NewShopAuthService.js'

const router = useRouter()

// 检查登录状态
onMounted(() => {
  if (!NewShopAuthService.isLoggedIn()) {
    // 如果未登录，跳转到登录页面
    router.push('/new-shop-login')
  }
})

// 返回首页
const backToHome = () => {
  router.push('/new-shop')
}

// 查看订单
const viewOrder = () => {
  // 实际应用中应该跳转到订单详情页或订单列表页
  alert('订单查看功能开发中...')
  router.push('/new-shop')
}
</script>

<template>
  <div class="new-shop-success-container">
    <!-- 导航栏 -->
    <nav class="new-shop-nav">
      <div class="nav-logo">
        <svg viewBox="0 0 24 24" width="24" height="24" stroke="#2196F3" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
          <circle cx="9" cy="21" r="1"></circle>
          <circle cx="20" cy="21" r="1"></circle>
          <path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
        </svg>
        <span>NewShop</span>
      </div>
    </nav>
    
    <!-- 主要内容 -->
    <main class="new-shop-success-main">
      <div class="success-content">
        <!-- 成功图标 -->
        <div class="success-icon">
          <svg viewBox="0 0 24 24" width="120" height="120" stroke="#4caf50" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
            <circle cx="12" cy="12" r="10"></circle>
            <polyline points="20 6 9 17 4 12"></polyline>
          </svg>
        </div>
        
        <!-- 成功信息 -->
        <div class="success-message">
          <h1>订单提交成功！</h1>
          <p>感谢您的购买，您的订单已经成功提交，我们会尽快为您发货。</p>
          
          <!-- 订单信息 -->
          <div class="order-info">
            <p class="order-number">订单编号：<span>20240620{{ Math.floor(Math.random() * 10000) }}</span></p>
            <p class="order-time">下单时间：<span>{{ new Date().toLocaleString('zh-CN') }}</span></p>
          </div>
          
          <!-- 操作按钮 -->
          <div class="action-buttons">
            <button class="view-order-button" @click="viewOrder">
              查看订单
            </button>
            <button class="continue-shopping-button" @click="backToHome">
              继续购物
            </button>
          </div>
          
          <!-- 推荐商品 -->
          <div class="recommended-products">
            <h3>猜您喜欢</h3>
            <div class="product-suggestions">
              <div class="suggestion-item">
                <div class="product-image">
                  <img src="https://picsum.photos/seed/product1/200/200" alt="推荐商品1" />
                </div>
                <div class="product-name">高端无线耳机</div>
                <div class="product-price">¥1299</div>
              </div>
              <div class="suggestion-item">
                <div class="product-image">
                  <img src="https://picsum.photos/seed/product2/200/200" alt="推荐商品2" />
                </div>
                <div class="product-name">智能手表</div>
                <div class="product-price">¥899</div>
              </div>
              <div class="suggestion-item">
                <div class="product-image">
                  <img src="https://picsum.photos/seed/product3/200/200" alt="推荐商品3" />
                </div>
                <div class="product-name">便携式充电宝</div>
                <div class="product-price">¥199</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    
    <!-- 页脚 -->
    <footer class="new-shop-footer">
      <div class="footer-bottom">
        <p>© 2024 NewShop. 保留所有权利。</p>
      </div>
    </footer>
  </div>
</template>

<style scoped>
.new-shop-success-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* 导航栏样式 */
.new-shop-nav {
  background-color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 15px 30px;
  display: flex;
  align-items: center;
}

.nav-logo {
  display: flex;
  align-items: center;
  font-size: 24px;
  font-weight: 700;
  color: #2196F3;
}

.nav-logo svg {
  margin-right: 10px;
}

/* 主要内容样式 */
.new-shop-success-main {
  flex: 1;
  padding: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.success-content {
  text-align: center;
  max-width: 800px;
  width: 100%;
}

/* 成功图标样式 */
.success-icon {
  margin-bottom: 40px;
  animation: scaleIn 0.5s ease-out;
}

@keyframes scaleIn {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 成功信息样式 */
.success-message h1 {
  font-size: 36px;
  color: #4caf50;
  margin: 0 0 20px 0;
  animation: fadeInUp 0.6s ease-out;
}

.success-message p {
  font-size: 18px;
  color: #666;
  margin: 0 0 30px 0;
  animation: fadeInUp 0.7s ease-out;
}

@keyframes fadeInUp {
  0% {
    transform: translateY(20px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 订单信息样式 */
.order-info {
  background-color: #f5f5f5;
  border-radius: 12px;
  padding: 25px;
  margin-bottom: 30px;
  animation: fadeInUp 0.8s ease-out;
}

.order-number,
.order-time {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: #333;
}

.order-number:last-child,
.order-time:last-child {
  margin-bottom: 0;
}

.order-number span,
.order-time span {
  font-weight: 600;
  color: #2196F3;
}

/* 操作按钮样式 */
.action-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 50px;
  animation: fadeInUp 0.9s ease-out;
}

.view-order-button,
.continue-shopping-button {
  padding: 12px 40px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.view-order-button {
  background-color: #2196F3;
  color: white;
}

.view-order-button:hover {
  background-color: #1976D2;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.continue-shopping-button {
  background-color: white;
  color: #2196F3;
  border: 2px solid #2196F3;
}

.continue-shopping-button:hover {
  background-color: #2196F3;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

/* 推荐商品样式 */
.recommended-products {
  animation: fadeInUp 1s ease-out;
}

.recommended-products h3 {
  font-size: 24px;
  color: #333;
  margin: 0 0 30px 0;
}

.product-suggestions {
  display: flex;
  justify-content: center;
  gap: 30px;
  flex-wrap: wrap;
}

.suggestion-item {
  width: 200px;
  border: 1px solid #eee;
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  background-color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.suggestion-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.product-image {
  width: 100%;
  height: 200px;
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.suggestion-item:hover .product-image img {
  transform: scale(1.1);
}

.product-name {
  padding: 15px;
  font-size: 16px;
  color: #333;
  font-weight: 600;
  text-align: center;
}

.product-price {
  padding: 0 15px 15px;
  font-size: 18px;
  color: #2196F3;
  font-weight: 700;
  text-align: center;
}

/* 页脚样式 */
.new-shop-footer {
  background-color: #333;
  color: white;
  padding: 30px;
  margin-top: auto;
}

.footer-bottom {
  text-align: center;
  font-size: 14px;
  color: #999;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .new-shop-success-main {
    padding: 20px;
  }
  
  .success-message h1 {
    font-size: 28px;
  }
  
  .success-message p {
    font-size: 16px;
  }
  
  .action-buttons {
    flex-direction: column;
    gap: 15px;
  }
  
  .view-order-button,
  .continue-shopping-button {
    width: 100%;
  }
  
  .product-suggestions {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }
  
  .suggestion-item {
    width: 100%;
    max-width: 300px;
  }
}
</style>